{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use Case 19\n",
    "==========\n",
    "\n",
    "Problem Definition:\n",
    "-------------------\n",
    "\n",
    "A climate scientist wishes to analyse potential correlations between *Ozone* and *Cloud* ECVs.\n",
    "\n",
    "Required Toolbox Features:\n",
    "--------------------------\n",
    "\n",
    "* Access to and ingestion of ESA CCI GHG data\n",
    "* Selection of required products/variables\n",
    "* Temporal and spatial subsetting\n",
    "* Generation of maps/animations depicting the evolution of GHG emissions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Ingest data and create the dataset\n",
    "-------------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cate.ops as ops\n",
    "from cate.core.ds import DATA_STORE_REGISTRY\n",
    "from cate.util.monitor import ConsoleMonitor\n",
    "from IPython.core.display import display, HTML\n",
    "\n",
    "monitor = ConsoleMonitor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# As CCI GHG L3 level data is not found in the esa cci odp remote repository, we'll look at ozone\n",
    "data_store = DATA_STORE_REGISTRY.get_data_store('esa_cci_odp')\n",
    "oz_remote_sources = data_store.query('esacci.OZONE.mon.L3.NP.multi-sensor.multi-platform.MERGED.fv0002.r1')\n",
    "oz_remote_sources"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# To reduce bandwith select the region of interest, time range and variables right away\n",
    "europe = 'POLYGON((-12.05078125 73.54664369613808,33.65234375 73.54664369613808,33.65234375 35.65604583948963,-12.05078125 35.65604583948963,-12.05078125 73.54664369613808))'\n",
    "oz_remote_sources[0].make_local(local_name='ozone-europe.mon.2007.2008',\n",
    "                                time_range='2007-01-01, 2008-12-31',\n",
    "                                var_names='O3_du_tot, O3_ndens',\n",
    "                                region=europe,\n",
    "                                monitor=monitor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "oz = ops.open_dataset('local.ozone-europe.mon.2007.2008')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "oz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "display(HTML(ops.animate_map(oz, var='O3_du_tot', region=europe, true_range=True, monitor=monitor)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Let's look at ozone density at different air pressures in April, 2017\n",
    "display(HTML(ops.animate_map(oz,\n",
    "                             var='O3_ndens',\n",
    "                             monitor=monitor,\n",
    "                             animate_dim='air_pressure',\n",
    "                             region=europe,\n",
    "                             true_range=True,\n",
    "                             indexers={'time':'2007-04-01'})))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
